package com.ruoyi.web.controller.manage;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.UserTerms;
import com.ruoyi.manage.service.IUserTermsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户条款Controller
 * 
 * @author ruoyi
 * @date 2021-03-08
 */
@RestController
@RequestMapping("/manage/terms")
public class UserTermsController extends BaseController
{
    @Autowired
    private IUserTermsService userTermsService;

    /**
     * 查询用户条款列表
     */
    @PreAuthorize("@ss.hasPermi('manage:terms:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserTerms userTerms)
    {
        startPage();
        List<UserTerms> list = userTermsService.selectUserTermsList(userTerms);
        return getDataTable(list);
    }

    /**
     * 导出用户条款列表
     */
    @PreAuthorize("@ss.hasPermi('manage:terms:export')")
    @Log(title = "用户条款", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserTerms userTerms)
    {
        List<UserTerms> list = userTermsService.selectUserTermsList(userTerms);
        ExcelUtil<UserTerms> util = new ExcelUtil<UserTerms>(UserTerms.class);
        return util.exportExcel(list, "terms");
    }

    /**
     * 获取用户条款详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:terms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userTermsService.selectUserTermsById(id));
    }

    /**
     * 新增用户条款
     */
    @PreAuthorize("@ss.hasPermi('manage:terms:add')")
    @Log(title = "用户条款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserTerms userTerms)
    {
        return toAjax(userTermsService.insertUserTerms(userTerms));
    }

    /**
     * 修改用户条款
     */
    @PreAuthorize("@ss.hasPermi('manage:terms:edit')")
    @Log(title = "用户条款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserTerms userTerms)
    {
        return toAjax(userTermsService.updateUserTerms(userTerms));
    }

    /**
     * 删除用户条款
     */
    @PreAuthorize("@ss.hasPermi('manage:terms:remove')")
    @Log(title = "用户条款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userTermsService.deleteUserTermsByIds(ids));
    }
}
